<template>
  <div>
    <a-row :gutter="24" style="margin-bottom: 15px;margin-top: 20px;">
      <a-col :span="6">
        <div class="dashboard-card">
          <div class="card-header">
            <div class="card-title">生效中总数</div>
            <div class="card-icon  card-blue">
              <a-icon type="shop" />
            </div>
          </div>
          <div class="card-value">{{ cardData.sxCount }}</div>
          <div class="card-desc">生效中合同数量</div>
        </div>
      </a-col>
      <a-col :span="6">
        <div class="dashboard-card">
          <div class="card-header">
            <div class="card-title">已到期总数</div>
            <div class="card-icon card-orange">
              <a-icon type="home" />
            </div>
          </div>
          <div class="card-value">{{ cardData.yxCount }}</div>
          <div class="card-desc">已到期合同数量</div>
        </div>
      </a-col>
      <a-col :span="6">
        <div class="dashboard-card">
          <div class="card-header">
            <div class="card-title">已终止总数</div>
            <div class="card-icon card-green">
              <a-icon type="setting" />
            </div>
          </div>
          <div class="card-value">{{cardData.zcCount}}</div>
          <div class="card-desc">已终止合同数量</div>
        </div>
      </a-col>
      <a-col :span="6">
        <div class="dashboard-card">
          <div class="card-header">
            <div class="card-title">签定中总数</div>
            <div class="card-icon card-purple">
              <a-icon type="bar-chart" />
            </div>
          </div>
          <div class="card-value">{{ cardData.qdCount }}</div>
          <div class="card-desc">签定中合同数量</div>
        </div>
      </a-col>
    </a-row>
    <a-card :bordered="false">
      
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24" class="section-header">
            <a-col :span="16" class="section-title">
              <a-icon type="unordered-list" /> 合同清单
            </a-col>
            <a-col :span="8" style="text-align: right;">
              <a-button @click="handleAdd" type="primary" v-has="'assetContractInfo:add'" class="list-button" icon="plus">新增</a-button>
              <a-button type="primary" v-has="'assetContractInfo:exportXls'" icon="download" class="list-button" @click="handleExportXls('合同台账')">导出</a-button>
              <a-upload name="file" v-has="'assetContractInfo:importExcel'" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
                <a-button type="primary" icon="import">导入</a-button>
              </a-upload>
            </a-col>
          </a-row>
          <!-- 查询区域 -->
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="合同编号">
                <a-input placeholder="请输入合同编号" v-model="queryParam.contractCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="合同名称">
                <a-input placeholder="请输入合同名称" v-model="queryParam.contractName"></a-input>
              </a-form-item>
            </a-col>
            <template v-if="toggleSearchStatus">
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="合同类型">
                  <j-dict-select-tag placeholder="请选择合同类型" v-model="queryParam.contractType" dictCode="contract_type"/>
                </a-form-item>
              </a-col>
            </template>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                <a @click="handleToggleSearch" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->

      <!-- table区域-begin -->
      <div>
        <a-table
          ref="table"
          size="middle"
          :scroll="{x:true}"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          @change="handleTableChange">

          <template slot="htmlSlot" slot-scope="text">
            <div v-html="text"></div>
          </template>
          <template slot="imgSlot" slot-scope="text,record">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
            <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </template>
          <template slot="fileSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
            <a-button
              v-else
              :ghost="true"
              type="primary"
              icon="download"
              size="small"
              @click="downloadFile(text)">
              下载
            </a-button>
          </template>

          <span slot="action" slot-scope="text, record">
            <a @click="handleDetail(record)">详情</a>
            <a-divider v-has="'assetContractInfo:edit'" type="vertical" />
            <a v-has="'assetContractInfo:edit'" @click="handleEdit(record)">编辑</a>
            <a-divider v-has="'assetContractInfo:delete'" type="vertical" />
            <a-popconfirm v-has="'assetContractInfo:delete'" :title="'确定删除，合同'+record.contractName+'（'+record.contractCode+'）吗？'" @confirm="() => handleDelete(record.id)">
              <a style="color: red">删除</a>
            </a-popconfirm>
          </span>

        </a-table>
      </div>

      <asset-contract-info-modal ref="modalForm" @ok="modalFormOk"></asset-contract-info-modal>
      <asset-contract-info-view-modal ref="modalView" @edit="handleEdit" @ok="modalFormOk"></asset-contract-info-view-modal>
    </a-card>
  </div>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import AssetContractInfoModal from './modules/AssetContractInfoModal'
  import AssetContractInfoViewModal from './modules/AssetContractInfoViewModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { httpAction, getAction } from '@/api/manage'

  export default {
    name: 'AssetContractInfoList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      AssetContractInfoModal,
      AssetContractInfoViewModal
    },
    data () {
      return {
        description: '合同信息管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'合同编号',
            align:"center",
            dataIndex: 'contractCode'
          },
          {
            title:'合同名称',
            align:"center",
            dataIndex: 'contractName'
          },
          {
            title:'合同类型',
            align:"center",
            dataIndex: 'contractType_dictText'
          },
          // {
          //   title:'签约主体',
          //   align:"center",
          //   dataIndex: 'signingSubject'
          // },
          {
            title:'合同金额（元）',
            align:"center",
            dataIndex: 'contractAmount'
          },
          {
            title:'合同开始日期',
            align:"center",
            dataIndex: 'contractStartDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'合同结束日期',
            align:"center",
            dataIndex: 'contractEndDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'合同状态',
            align:"center",
            dataIndex: 'contractStatus_dictText'
          },
          // {
          //   title:'付款日期',
          //   align:"center",
          //   dataIndex: 'paymentDate',
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/asset/assetContractInfo/list",
          delete: "/asset/assetContractInfo/delete",
          deleteBatch: "/asset/assetContractInfo/deleteBatch",
          exportXlsUrl: "/asset/assetContractInfo/exportXls",
          importExcelUrl: "asset/assetContractInfo/importExcel",
          cardTotal: "/asset/assetContractInfo/cardTotal",
          
        },
        dictOptions:{},
        superFieldList:[],
        cardData:{
          sxCount:0,
          yxCount:0,
          zcCount:0,
          qdCount:0,
        }
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      loadDataEnd(){
        getAction(this.url.cardTotal, {}).then((res) => {
          if (res.success) {
            this.cardData = res.result;
          }
        });
      },
      handleDetail:function(record){
        record.canEdit = true;
        this.$refs.modalView.edit(record);
        this.$refs.modalView.title="合同详情";
        this.$refs.modalView.disableSubmit = true;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .dashboard-card {
    background: white;
    border-radius: 10px;
    padding: 15px 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s, box-shadow 0.3s;
  }
  .dashboard-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  }
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
  }
  .card-title {
    font-size: 18px;
    color: #555;
    font-weight: 600;
  }
  .card-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
  }
  .card-value {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    margin-bottom: 5px;
  }
  .card-desc {
    color: #777;
    font-size: 0.9rem;
  }
  .card-blue {
    background: linear-gradient(45deg, #2196F3, #21CBF3);
  }
  .card-orange {
    background: linear-gradient(45deg, #FF9800, #FFC107);
  }
  .card-green {
    background: linear-gradient(45deg, #4CAF50, #8BC34A);
  }
  .card-purple {
    background: linear-gradient(45deg, #9C27B0, #E91E63);
  }
  .list-button {
      margin: 0 8px 8px 0;
  }
  .section-header{
    margin-bottom: 20px;
  }
  .section-title{
    font-size: 20px;
    color: #333;
    font-weight: 600;
  }
</style>